package com.ysstech.activiti.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.ysstech.activiti.service.ActivitiTaskService;
import com.ysstech.common.controller.BaseController;
import com.ysstech.common.entity.Role;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 流程任务管理 ,跳转到对应的审批页面
 */
@Controller
@RequestMapping(value = "/approve")
@Slf4j
public class ApproveActivitiController extends BaseController {
    @Autowired
    private ActivitiTaskService activitiTaskService;

    /**
     * 一：使用任务I
     */
    @RequestMapping(value = "/findTaskId")
    public String findTaskId(String taskId, String assignee, HttpServletRequest request) throws Exception {
        Map<String, Object> map = activitiTaskService.queryObjId(taskId);
        if (null != map && map.size() > 0) { //角色的流程
            request.setAttribute("taskId", taskId);
            request.setAttribute("key", map.get("key"));
            request.setAttribute("isassignee", redisCacheManager.getLoginUserInfo().getLoginId().equals(assignee)); //流程发起人
            if ("role".equalsIgnoreCase((String) map.get("key"))) {
                Role role = new Role();
                role.setName("新增角色");
                role.setType(1);
                role.setDescription("测试流程角色");
                role.setOrgId("中国银行总行");
                request.setAttribute("role", role);
                // Role role = roleService.selectByPrimaryKey((String) map.get("objId"));
                // request.setAttribute("role", role);
                return "activiti/roleworkflow";//打开角色审核页面
            }
        }
        return "404";
    }


}
